home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / 3DVIS10.ZIP / 3DVISION.DOC < prev    next >
Text File  |  1996-02-29  |  17KB  |  413 lines

  1.         _____     _       _     _                  _
  2.        |___ /  __| |_   _(_)___(_) ___  _ __    __| | ___   ___
  3.          |_ \ / _` \ \ / / / __| |/ _ \| '_ \  / _` |/ _ \ / __|
  4.         ___) | (_| |\ V /| \__ \ | (_) | | | || (_| | (_) | (__
  5.        |____/ \__,_| \_/ |_|___/_|\___/|_| |_(_)__,_|\___/ \___|
  6.  
  7.  
  8. ------------
  9. INTRODUCTION
  10. ------------
  11.  
  12.     3DVISION is a set of programs that display 3-dimensional objects and allow
  13. you to make real-time rotations with them. It  works  on  IBM AT  compatibles,
  14. with EGA or VGA videos.
  15.  
  16.     3DVISION was inspired on  the  3DV.EXE  program, written  by  Oscar García
  17. from New Zealand. 3DVISION  has  some  capabilities  that  3DV  doesn't  have,
  18. as  the  ramdom  displaying  of objects on screen, and the changing of colors.
  19. However, the  original  3DV.EXE  runs at a  faster  rate and has a better user
  20. interface. The  3DVISION and 3DV data files are 100% compatible. You  can  get
  21. the 3DV  program  at  the  SimTel's  msdos/graphics  subdirectory or from many
  22. others sites with names that look like 3DV25.ZIP or 3DKIT1.ZIP.
  23.  
  24.     The package  3DVISION contains the executables  3DVISION.EXE, 3DVRAND.EXE,
  25. 3DVSURF.EXE,  3DVCOLOR.COM, RNDCOLOR.COM and  about  40  data files containing
  26. 3D objects, all  of  them  constructed  on  mathematical parametric curves and
  27. surfaces equations. See the end of each *.3DV data file to get  the  equations
  28. used (this can be made writting C:\> COMMENT file_name[.3dv]).
  29.  
  30.     All the programs  were written and compiled with  the  old  Turbo  C  2.0.
  31. I  did  purchased the Borland C++ 4.0 license on december/1994, but I am still
  32. without courage to learn how it works.
  33.  
  34.     Press the ESC  key to quit any of the programs. When the mouse is enabled,
  35. press  any  buttom to quit.  All of  the  programs will use the extension .3DV
  36. as default, that is, you don't need to append it.
  37.  
  38.  
  39. ------------
  40. 3DVISION.EXE
  41. ------------
  42.  
  43.     The main program is  3DVISION.EXE. It displays the objects saved in  *.3DV
  44. files. It can works with the keyboard or with  the  mouse.  You  can alternate
  45. the  usage between keyboard/mouse only using the configuration files  (see the
  46. item CONFIGURATION below).
  47.     Data files are given as parameters at the DOS command line:
  48.  
  49.          C:\>  3DVISION Data_File [Config_File]
  50. where
  51.     Data_file is a text file with the scene description in 3DV format
  52. and
  53.     Config_File is an optional parameter with the configuration file name
  54.  
  55.     After the displaying, press one of the following keys:
  56.  
  57.       Right, left arrows:         Rotate around the z axis
  58.       Up, down arrows:            Rotate around the y axis
  59.       Ctrl-up, Ctrl-down arrows:  Rotate around the x axis
  60.       PgDn, PgUp:                 Zoom in/out
  61.       F1:                         Change ramdomly the colors
  62.       F2:                         Save the new colors (on files whose
  63.                        extensions are .1, .2, .3, ...)
  64.       ESC:                        Quit
  65.  
  66.     Type 3DVISION ?,  3DVISION /?  or  3DVISION /h  at the DOS prompt to get a
  67. brief help screen.
  68.  
  69. Example: To display a file named CURVE1.3DV using the default configuration or
  70. the standard configuration file 3DVISION.CFG, just type
  71.              C:\> 3DVISION curve1
  72.     To display  the same file  using the  configuration file  CONFIG.CFG, type
  73.              C:\> 3DVISION curve1 config
  74.  
  75.  
  76. -----------
  77. 3DVRAND.EXE
  78. -----------
  79.  
  80.     3DVRAND displays a selected object on screen rotating it randomly.  During
  81. the execution, press any key to freeze the image. Then, press another  key  to
  82. continue the ramdom rotations.
  83.     The usage is the same as 3DVISION.EXE:
  84.  
  85.            C:\> 3DVRAND Data_File [Config_File]
  86.  
  87.      To get a help screen, type  3DVRAND ?  or  3DVRAND /h  at the DOS prompt.
  88.  
  89.  
  90. -----------
  91. 3DVSURF.EXE
  92. -----------
  93.  
  94.     3DVSURF creates a 3DV file with points of a given  surface  in  parametric
  95. form F(x, y) = (f1(x, y), f2(x, y), f3(x, y)). You can give the optional names
  96. of the variables  as  parameters (default = "x" and "y").  Hidden  curves  are
  97. displayed.
  98.  
  99.     The usage is: 3DVSURF file_name[.3DV] [variable_1] [variable_2]
  100.  
  101.     Using this parametric form, functions z = G(x, y) can be given as
  102.                f1(x, y) = x
  103.                f2(x, y) = y
  104.                f3(x, y) = G(x, y)
  105.  
  106.     The  valid  operations are + (addition),  - (subtraction),  * (multiplica-
  107. tion),  / (division)  and  ^ (power).
  108.     The valid functions  are the  trigonometric  SIN,  COS,  TG;  the  inverse
  109. trigonometric ARCSIN, ARCCOS, ARCTG; the natural logarithm LN; the exponential
  110. EXP; the hyperbolic  SINH,  COSH, TGH;  the  approximations  to integers  INT,
  111. ROUND;  the  square  root SQRT; the square SQR; the absolute value ABS and the
  112. SIGN function.
  113.     Examples of valid expressions are:  3*sin(x)*cos(y),  (1 + (1 - x^2)/5)^2,
  114. (1 - u*cos(u))*sin(2*v)/3   and  sqrt(abs(0.5 + round(u + v))).
  115.     You  have to give  the  [minimum, maximum] values of the variables and the
  116. number of subdivisions of these intervals.
  117.  
  118. Example: Write at the DOS prompt
  119.                C:\> 3DVSURF  graph  u  v
  120. to create  a  file  named  GRAPH.3DV  with  the  points of the graphics of the
  121. surface  F(u, v) = (f1(u, v), f2(u, v), f3(u, v)),  where  f1, f2, f3  will be
  122. asked later.
  123.  
  124.  
  125. ------------
  126. 3DVCOLOR.COM
  127. ------------
  128.  
  129.     3DVCOLOR is a simple  utility to change the colors of 3DV files. The  file
  130. names must be given as two parameters. The usage is:
  131.  
  132.        C:\> 3DVCOLOR  Source_file[.3DV]  Destination_file[.3DV]
  133.  
  134. where
  135.     Source_file is the file that originally contains the objects
  136.  and
  137.     Destination_file will be created by 3DVCOLOR and contains the same
  138.                          objects with new selected colors.
  139.  
  140.     The contents of the source_file remain unchanged.
  141.  
  142.     You  can  select  the  colors using the rigth and left arrows and pressing
  143. the ENTER key.
  144.  
  145. Example:  To  create  a  file  named  FILE2.3DV  with  different  colors  from
  146. another file FILE1.3DV previously saved on disk, write
  147.             C:\> 3DVCOLOR file1 file2
  148.     Then, you will be asked which colors you want to change.
  149.  
  150.  
  151. ------------
  152. RNDCOLOR.COM
  153. ------------
  154.  
  155.     RNDCOLOR  changes  ramdomly the  colors on a .3DV file. Its  usage  is the
  156. same as 3DVCOLOR - just give the name of the files as parameters:
  157.  
  158.         C:\> RNDCOLOR  original_3DV_file  new_3DV_file
  159.  
  160. Example: Using  the file  OLDLINES.3DV as source, RNDCOLOR  creates a new file
  161. called NEWLINES.3DV with the same scene, but with randomly changed colors:
  162.         C:\> RNDCOLOR  OldLines.3dv  NewLines.3dv
  163.  
  164.  
  165. -------------
  166. CONFIGURATION
  167. -------------
  168.  
  169.     You  can  define  one  or  various  configuration  files to  3DVISION  and
  170. 3DVRAND.  The  standard  configuration  file is 3DVISION.CFG. The default file
  171. extension is .CFG.
  172.     When 3DVISION or 3DVRAND begin running, the first thing they do is to look
  173. for a file named  3DVISION.CFG.  If  they  find  this file, they interpret its
  174. lines one by  one. Later,  these  programs  verify  whether  there is a second
  175. configuration file name, given as a second parameter. If there is such  second
  176. file, it will be opened and executed. For example, if you  write  at  the  DOS
  177. prompt
  178.  
  179.            C:\> 3DVISION  house.3dv  config2.cfg
  180.  
  181. then, 3DVISION will display HOUSE.3DV  using  the  configuration  of the files
  182. 3DVISION.CFG (the standard) and CONFIG2.CFG. The commands in CONFIG2.CFG  will
  183. overwrite those of 3DVISION.CFG.  The  configuration  files don't need to have
  184. the same commands - they can compensate each other.
  185.     To  create  a configuration  file,  use  any  text  editor.  Even the COPY
  186. command of DOS can be used  (write  COPY CON Config_File_Name  and press F6 at
  187. the end). Beware  of  special  characters that some text editors append to the
  188. files.
  189.     Comments can be added, written after a semicolon.
  190.     Some options of 3DVISION or 3DVRAND can be changed only using a configura-
  191. tion file.  The  mouse/keyboard  usage  and  the  method of projection are two
  192. examples of options that cannot be changed after  the  beginning of execution.
  193.    The  configuration file can have the following commands.  N  is  a  natural
  194. number. No matter if are used upper or lower case letters.
  195.  
  196. Command            What it does
  197. ----------------   -----------------------------------------------------------
  198. mouse = 1 or 0     Enables  (mouse = 1)  or  disables  the  mouse  usage.  The
  199.            default is mouse = 0.
  200.  
  201. size = N           Size of the objects.  If size <= 170, then the objects will
  202.            not be clipped. The default is size = 170.
  203.  
  204. method = 1 or 0    Defines the method  of  projection  of  the  3D objects. If
  205.            method = 0 (default), parallel (orthogonal) projection will
  206.            be  used. If  method = 1,  a perspective projection will be
  207.            used.
  208.  
  209. file = File_Name   File name in 3DV format to be displayed.
  210.  
  211. bottom = 1 or 0    Displays or not a status  line at the lower part of screen.
  212.            The status line contains the file name being used  and  the
  213.            variation of the rotation angles. The default is bottom =1.
  214.  
  215. theta = N          Rotation around the z  axis  increment  (in  degrees).  The
  216.            default is theta = 1°.
  217.  
  218. phi = N            Rotation around the  y  axis  increment  (in degrees).  The
  219.            default is phi = 1°.
  220.  
  221. sigma = N          Rotation around  the  x  axis increment  (in degrees).  The
  222.            default is sigma = 1°.
  223.  
  224. delay = N          Pause (in milliseconds)  between  two  images. Used only by
  225.            3DVRAND. The default is delay = 50.
  226.  
  227. sensibility = N    Mouse sensibility. The default is sensibility = 50.
  228.  
  229. proj = N           The norm of orthogonal  vectors  that  are the basis of the
  230.            mouse movement plane. The default is proj = 1.
  231.  
  232. lim1 = N           Maximum random number of multiples of increments of  theta.
  233.            Used only by 3DVRAND. The default is lim1 = 10.
  234.  
  235. lim2 = N           Maximum random number of  multiples of increments  of  phi.
  236.            Used only by 3DVRAND. The default is lim2 = 10.
  237.  
  238. lim3 = N           Maximum random number of  multiples of increments of sigma.
  239.            Used only by 3DVRAND. The default is lim3 = 10.
  240.  
  241.  
  242. --------------
  243. THE 3DV FORMAT
  244. --------------
  245.  
  246.     A  3DV data file  is a text (ASCII) file  that contains  a list of points,
  247. followed by a list of moving or drawing instructions.  It  has  the  following
  248. structure:
  249.  
  250.        N                    Total number of points to be drawn
  251.        x1  y1  z1           1st. point
  252.        x2  y2  z2           2nd. point
  253.        ...                  ...
  254.        xN  yN  zN           The last point
  255.        M                    Total number of movements or drawings
  256.        p1  c1               1st. movement or drawing
  257.        p2  c2               2nd. movement or drawing
  258.        ...                  ...
  259.        pM  cM               The last movement or drawing
  260.  
  261. where
  262.  
  263. ■ (xi, yi, zi) are the coordinates of the i-th point in 3D space
  264.  
  265. ■ (p1, p2, ..., pM) is a sequence  of  integers  greater  than or equal to  1.
  266.   It defines the order in which the points will be drawn or the one  which  it
  267.   will be moved to. The first point to be actually drawn  or moved  to  is the
  268.   p1-th point, the second is the p2-th point and so on.
  269.  
  270. ■ (c1, c2, ..., cM)  are  their  respective  colors.  They  are integers  from
  271.   0  to  15  (1 = blue, 2 = green, 3 = cyan, ..., 15 = white).
  272.  
  273. ■ If  ci = 0  then it means a movement to the pi-th point. If ci is not  0, it
  274.   means a color number and that you have to draw a line from the current point
  275.   to the pi-th point using the color ci.
  276.  
  277. Example: A yellow (color = 14) cube with vertices  (-1, -1, -1),  (-1, 1, -1),
  278. (1, 1, -1),  (1, -1, -1),  (-1, -1, 1),  (-1, 1, 1), (1, 1, 1), (1, -1, 1) can
  279. be described in 3DV format as
  280.  
  281.                8
  282.               -1   -1   -1
  283.               -1    1   -1
  284.                1    1   -1
  285.                1   -1   -1
  286.               -1   -1    1
  287.               -1    1    1
  288.                1    1    1
  289.                1   -1    1
  290.                16
  291.                1    0
  292.                2   14
  293.                3   14
  294.                4   14
  295.                1   14
  296.                5   14
  297.                6   14
  298.                7   14
  299.                8   14
  300.                5   14
  301.                2    0
  302.                6   14
  303.                3    0
  304.                7   14
  305.                4    0
  306.                8   14
  307.  
  308.  
  309. --------------------------
  310. PROJECTIVE TRANSFORMATIONS
  311. --------------------------
  312.  
  313.     Projections of  points in 3D space to a plane constitute  a  simple  topic
  314. that some books and some persons use to complicate.
  315.     The projections can be classified in parallel  or  in  perspective.  In  a
  316. parallel projection, the objects are not deformed because the  projection rays
  317. are parallel. In the perspective type, the projection rays  are  not  parallel
  318. and you can see vanishing points.
  319.     The simplest parallel projections are the 'orthographic' ones. They simply
  320. annul the information in one coordinate, e.g. as  T(x, y, z) = (0, y, z).
  321.     You can get good results with  the  'axonometric'  projections.  They  are
  322. rotations followed by an orthographic projection. An example of an axonometric
  323. projection (in matrix form) is:
  324.  
  325.                ┌  cos Θ   sin Θ  0 ┐┌  cos φ  0   sin φ ┐┌ 0  0  0 ┐
  326.    T(x,y,z) = [ x y z ]│ -sin Θ   cos Θ  0 ││    0    1     0   ││ 0  1  0 │
  327.                └   0        0    1 ┘└ -sin φ  0   cos φ ┘└ 0  0  1 ┘
  328.  
  329. that is,  T(x, y, z)  =  (0, x sin Θ + y cos φ,
  330.                       x cos Θ sin φ - y sin Θ sin φ + z cos φ)
  331.  
  332.     Thus, if you want to plot the point (x, y, z) in  3D  space, just plot the
  333. point  ( x sin Θ + y cos φ,  x cos Θ sin φ - y sin Θ sin φ + z cos φ)  on  the
  334. yOz plane.  Here, Θ and φ are the rotation angles (in radians) about the z and
  335. y axis.
  336.     If you want to rotate σ radians around the x axis too, just add the matrix
  337.  
  338.                ┌  1      0       0    ┐
  339.                │  0    cos σ   sin σ  │
  340.                └  0   -sin σ   cos σ  ┘
  341.  
  342. as the fourth factor on the matrix product above.
  343.  
  344.     Thereby, you can use the following steps to plot a point (x, y, z):
  345.  
  346.     (1) Get the values of (x, y, z), reading them on the file.
  347.  
  348.     (2) Project (x, y, z)   on  a   plane,   using  an   axonometric   (or   a
  349.     perspective) projection.  This  can be made by calling  the   function
  350.     ProjectPoint(x, y, z, &X, &Y). The C source to ProjectPoint() can  be:
  351.  
  352.     void ProjectPoint(float x, float y, float z,
  353.                        int *X_proj, int *Y_proj) {
  354.       float Y, Z;
  355.       Y = x*sin(theta) + y*cos(theta);
  356.       Z = (x*cos(theta) - y*sin(theta))*sin(phi) + z*cos(phi);
  357.       *X_proj = (int) (A + Size*Y);
  358.       *Y_proj = (int) (B - Size*Z);
  359.     }
  360.  
  361.     where
  362.     ■ A, B, theta, phi and Size are global variables.
  363.     ■ (A, B) are screen coordinates chosen as the origin of the  cartesian
  364.       system.
  365.     ■ theta and phi are the rotation  angles  around the  z  and  y  axis.
  366.  
  367.     (3) Draw the (X, Y) point on screen: putpixel(X, Y, color).
  368.  
  369.     There are  too  many  books  about projections. I would like to refer only
  370. two, both from the McGraw-Hill catalogue:
  371.  
  372.           "Theory and problems of Computer Graphics"
  373.            (Schaum's Outline Series)
  374.            R. Plastock, G. Kalley
  375.  and
  376.           "Mathematical Elements for Computer Graphics"
  377.            D. Rogers, J. Adams
  378.  
  379.  
  380. -----------
  381. FINAL WORDS
  382. -----------
  383.  
  384.      These  programs may not be sold or included in another software. However,
  385. the  complete  3DVIS10.ZIP  file may be copied and widely distributed, keeping
  386. the original files and credits immutable.
  387.  
  388.      These programs were tested a large number of times and it is my hope that
  389. they  will  work  properly.  The  author  of  these  simple  programs  is  not
  390. responsible for any damage supposedly caused for their misusage. Use  them  by
  391. your own  risk.  You  wouldn't expect me to say something here different  from
  392. this, would you?
  393.  
  394.      Comments  and  suggestions  are  welcome  and  will  be  appreciated.  My
  395. eletronic   mail  is   CCENDM03@TERRA.NPD.UFPB.BR   or  CCENDM03@BRUFPB.BITNET
  396. (note  that  the  character  0 is zero).  Like  many  things here  in  Brazil,
  397. it doesn't work as it should do. So, sometimes I don't receive  messages  sent
  398. to me. Under normal conditions, I always reply ALL the messages that reach me.
  399.  
  400.     My thanks to professor Antônio Sales da Silva who made precious hints  and
  401. some corrections to the text in English.
  402.  
  403.     3DVISION  is  freeware, completely free of charges. But, if you  like  it,
  404. I would be very pleased to receive a postcard from your city.
  405.  
  406. ┌────────────────────────────────────────────────────────────────────────────┐
  407. │  Lenimar Nunes de Andrade                                                  │
  408. │  Rua Lindolfo Chaves, 381                                                  │
  409. │  58051-200 Joao Pessoa, PB - BRAZIL                                        │
  410. │                                                                            │
  411. │  *** At the most easterly place in our poor and beloved South America ***  │
  412. └────────────────────────────────────────────────────────────────────────────┘
  413.